home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / ScriptExplorer / CLG_AnimBanner.cp next >
Encoding:
Text File  |  1997-07-24  |  3.4 KB  |  165 lines  |  [TEXT/CWIE]

  1. // CLG_AnimBanner.cp
  2. //
  3. //        Pane subClass to display an animated sequence of PICTs
  4. //        Uses a Periodical to make the animation happen.
  5. //
  6. //    24jul97     bh
  7. //****************************************************************************
  8.  
  9. #ifdef PowerPlant_PCH
  10. #include PowerPlant_PCH
  11. #endif
  12.  
  13. // system headers
  14. #include <Script.h>
  15.  
  16. // PowerPlant headers
  17. #include <LStream.h>
  18. #include <UDrawingState.h>
  19.  
  20. // project headers
  21. #include "LG_Constants.h"
  22. #include "CLG_AnimBanner.h"
  23.  
  24.  
  25. //****************************************************************************
  26. #define kBasePICT    990
  27. #define kNumPICTs    8
  28. #define kDrawTime    (30*1)
  29.  
  30.  
  31. //***********************
  32. //    CreateDisplayStream
  33. //****************************************************************************
  34. CLG_AnimBanner*
  35. CLG_AnimBanner::CreateDisplayStream(
  36.     LStream    *inStream)
  37. {
  38.     return (new CLG_AnimBanner(inStream));
  39. }
  40.  
  41.  
  42. //***********************
  43. //    CLG_AnimBanner
  44. //****************************************************************************
  45. CLG_AnimBanner::CLG_AnimBanner(void)
  46. {
  47.     this->Init();
  48.     return;
  49. }
  50.  
  51. //***********************
  52. //    CLG_AnimBanner
  53. //****************************************************************************
  54. CLG_AnimBanner::CLG_AnimBanner( LStream *inStream)
  55.     : LPane( inStream)
  56. {
  57.     this->Init();
  58.     return;
  59. }
  60.  
  61. //***********************
  62. //    Init
  63. //****************************************************************************
  64. void CLG_AnimBanner::Init(void)
  65. {
  66.     mLastDraw = TickCount();
  67.     mCurInd = kNumPICTs-1;    
  68.     mAnimOn = false;
  69.     mCurPicH = (PicHandle)GetResource( 'PICT', kBasePICT+mCurInd);
  70.     
  71.     this->StartIdling();
  72.  
  73.     return;
  74. }
  75.  
  76.  
  77. //***********************
  78. //    ClickSelf
  79. //****************************************************************************
  80. void
  81. CLG_AnimBanner::ClickSelf( const SMouseDownEvent &inMouseDown)
  82. {
  83.     mAnimOn = !mAnimOn;
  84.     return;
  85. }
  86.  
  87. //***********************
  88. //    SpendTime
  89. //
  90. //        OK, run through a sequence of PICTs, drawing each one after some
  91. //        constant delay.  Special case the last pair and alternate for
  92. //        some random time.  Stall afer the sequence to give the user a break!
  93. //
  94. //****************************************************************************
  95. void
  96. CLG_AnimBanner::SpendTime(
  97.     const EventRecord&    inMacEvent)
  98. {
  99.     
  100.     if ( mAnimOn && TickCount() >= mLastDraw + kDrawTime) {
  101.         
  102.         if ( mCurInd == kNumPICTs) {
  103.             if ( Random() % 16 == 0) {
  104.                 mCurInd = 0;
  105.                 mLastDraw = TickCount() + 60*5;
  106.             } else mCurInd--;
  107.         } else 
  108.             mCurInd++;
  109.  
  110.  
  111.         mCurPicH = (PicHandle)GetResource( 'PICT', kBasePICT+mCurInd);
  112.         mLastDraw = TickCount();
  113.         this->Refresh();
  114.     }
  115.     
  116.     return;
  117. }
  118.  
  119. //***********************
  120. //    AdjustCursorSelf
  121. //****************************************************************************
  122. void
  123. CLG_AnimBanner::AdjustCursorSelf(
  124.     Point                inPortPt ,
  125.     const EventRecord&    inMacEvent)
  126. {
  127.     Point    tPt;
  128.     static Rect savR = {0,0,0,0};
  129.  
  130.     tPt = inPortPt;
  131.     
  132.     CursHandle    theCursH = ::GetCursor( 2);
  133.     if (theCursH != nil) {
  134.         ::SetCursor(*theCursH);
  135.     }
  136. }
  137.  
  138.  
  139. //***********************
  140. //    DrawSelf
  141. //****************************************************************************
  142.  
  143. void CLG_AnimBanner::DrawSelf(void)
  144. {
  145.     Rect            dstR;
  146.     SDimension16    tFrame;
  147.  
  148.     GetFrameSize( tFrame);
  149.  
  150.     dstR.left = mFrameLocation.h;
  151.     dstR.top  = mFrameLocation.v;
  152.     dstR.right = dstR.left + tFrame.width;
  153.     dstR.bottom = dstR.top + tFrame.height;
  154.     
  155.         long t = TickCount();
  156.         while ( t == TickCount()) ;
  157.  
  158.     if ( mCurPicH != 0)
  159.         DrawPicture( mCurPicH, &dstR);
  160.  
  161.     return;
  162. }
  163.  
  164. //*****************************************************************************
  165.